﻿using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;

namespace StockAnalyst2.Converters
{
	internal class PositiveGreenNegativeRedConverter : IValueConverter
	{
		#region Attributes

		private static readonly Color _zeroColor;
		private static readonly Color _redColor;
		private static readonly Color _greenColor;

		#endregion

		#region Public Methods

		static PositiveGreenNegativeRedConverter()
		{
			_zeroColor = Color.FromRgb(0xB8, 0xB8, 0xB8);
			_redColor = Color.FromRgb(0xBC, 0x58, 0x58);
			_greenColor = Color.FromRgb(0x59, 0xBF, 0x59);
		}

		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			decimal decimalValue = Decimal.Parse(value.ToString());

			if (decimalValue > 0)
			{
				return new SolidColorBrush(_greenColor);
			}
			else if (decimalValue < 0)
			{
				return new SolidColorBrush(_redColor);
			}
			else
			{
				return new SolidColorBrush(_zeroColor);
			}
		}


		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotImplementedException();
		}

		#endregion
	}
}
